package main

import (
	"pipeline"
	"fmt"
	"os"
	"bufio"
)

func main() {
	const filename  = "small.in"
	const n  = 100000000
	file,err:=os.Create(filename)
	if err!=nil{
		panic(err)
	}
	defer file.Close()
	p:=pipeline.RandomSource(n)
	writer:=bufio.NewWriter(file)
	pipeline.WriterSink(writer,p)
	writer.Flush()
	file,err=os.Open(filename)
	if err!=nil{
		panic(err)
	}
	defer file.Close()
	p=pipeline.ReaderSource(bufio.NewReader(file),-1)
	count:=0
	for v:=range p{
		fmt.Printf("%d \n",v)
		count++
		if count>=100{
			break
		}
	}
}

func mergeDemo(){
	p:=pipeline.Merge(
		pipeline.InMemSort(pipeline.ArraySource(3,2,1,5,4)),
		pipeline.InMemSort(pipeline.ArraySource(3,2,1,5,4)))
	for v:=range p{
		fmt.Println(v)
	}
}
